package com.henry.chatkit.demo

import android.content.Intent
import android.os.Bundle
import android.os.Message
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.henry.chatkit.ChatKit
import com.henry.chatkit.conversation.ConversationInfo
import com.henry.chatkit.conversation.ConversationLayout
import com.henry.chatkit.messages.MessageExt

class MainActivity : AppCompatActivity() {

    private val conversationLayout: ConversationLayout by lazy { findViewById(R.id.conversation_layout) }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        ChatKit.instance.initKit(this)

        initData()

        conversationLayout.mAdapter.onItemClickListener = { view: View?, i: Int, conversation: ConversationInfo? ->
            val intent = Intent(this, ChatActivity::class.java)
            startActivity(intent)
        }

        conversationLayout.mAdapter.onItemLongClickListener = { view: View?, i: Int, conversation: ConversationInfo? ->

        }

    }

    fun initData() {
        val list = mutableListOf<ConversationInfo>()
        for (i in 1..5) {
            val conversation = ConversationInfo()
            conversation.id = i.toString()
            conversation.title = "222"
            val msg = MessageExt.buildTextMessage("11111")
            conversation.unRead = 10
//            conversation.iconUrlList = mutableListOf(
//                "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=366763321,1800567094&fm=26&gp=0.jpg",
//            )
            if (i == 3) {
                conversation.unRead = 10
                conversation.mode = ConversationInfo.ConversationMode.QQ
                conversation.iconUrlList = mutableListOf(
                        "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=366763321,1800567094&fm=26&gp=0.jpg",
                        "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=366763321,1800567094&fm=26&gp=0.jpg",
                        "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fa2.att.hudong.com%2F27%2F81%2F01200000194677136358818023076.jpg&refer=http%3A%2F%2Fa2.att.hudong.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1618372582&t=cc180e0a980f2db4e28da77261cb1bf2"
                )
            }
            if (i == 1) {
                val msg1 = MessageExt.buildImageMessage("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=366763321,1800567094&fm=26&gp=0.jpg", 200, 200)

                conversation.unRead = -1
                conversation.iconUrlList = mutableListOf(
                        "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=366763321,1800567094&fm=26&gp=0.jpg",
                        "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=366763321,1800567094&fm=26&gp=0.jpg",
                        "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=366763321,1800567094&fm=26&gp=0.jpg",
                        "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=366763321,1800567094&fm=26&gp=0.jpg",
                        "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=366763321,1800567094&fm=26&gp=0.jpg",
                        "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=366763321,1800567094&fm=26&gp=0.jpg",
                        "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=366763321,1800567094&fm=26&gp=0.jpg",
                        "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=366763321,1800567094&fm=26&gp=0.jpg",
                        "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=366763321,1800567094&fm=26&gp=0.jpg",
                        )
                conversation.atInfoText = "小玉: "
                conversation.top = true

            }
            if (i == 2) {
                conversation.mode = ConversationInfo.ConversationMode.QQ
                conversation.unRead = 1
            }
            list.add(conversation)
        }
        conversationLayout.reloadData(list)

    }
}